const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

/**
 * AI 大模型配置模型
 */
const AIModel = sequelize.define('AIModel', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    unique: true,
    comment: '模型名称'
  },
  display_name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '显示名称'
  },
  base_url: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: 'API 基础地址'
  },
  api_key: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: 'API 密钥'
  },
  model_name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '模型标识符'
  },
  max_tokens: {
    type: DataTypes.INTEGER,
    defaultValue: 2000,
    comment: '最大 token 数'
  },
  temperature: {
    type: DataTypes.FLOAT,
    defaultValue: 0.7,
    comment: '温度参数'
  },
  timeout: {
    type: DataTypes.INTEGER,
    defaultValue: 60000,
    comment: '超时时间（毫秒）'
  },
  is_active: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    comment: '是否激活'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '模型描述'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'ai_models',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  indexes: [
    {
      fields: ['is_active']
    },
    {
      unique: true,
      fields: ['name']
    }
  ]
});

module.exports = AIModel;
